package main

import (
	"fmt"
	"protobuf_demo/service"

	"google.golang.org/protobuf/proto"
)

func main() {

	user := &service.User{
		Username: "zhangsan",
		// Age:      18,
		// Password: "abc123",
	}

	// 序列化
	marshal, err := proto.Marshal(user)
	if err != nil {
		panic(err)
	}
	fmt.Println("marshal", marshal)

	// 反序列化
	newUser := &service.User{}
	err = proto.Unmarshal(marshal, newUser)
	if err != nil {
		panic(err)
	}
	fmt.Println(newUser.String())

}
